package com.doit.day03

import scala.io.Source

object _08_wordCount {
  def main(args: Array[String]): Unit = {
    /* val lines: Iterator[String] = Source.fromFile("data/word.txt").getLines()
     val array: Array[String] = lines.toArray
     //数组里面的元素存的是什么
     /*
     hello,hello,hi,hi
     hadoop,hadoop,hive,hive,hello
     hi,hi,hello
     hello,hello,hi,hi
     hadoop,hadoop,hive,hive,hello
     hi,hi,hello
     hello,hello,hi,hi
     hadoop,hadoop,hive,hive,hello
     hi,hi,hello
      */
     val words: Array[String] = array.flatMap((line: String) => {
       line.split(",")
     })

     val map: Map[String, Array[String]] = words.groupBy((word: String) => {
       word
     })

     val res: Map[String, Int] = map.map((tp: (String, Array[String])) => {
       (tp._1, tp._2.size)
     })

     res.foreach(println)*/
    Source.fromFile("data/word.txt")
      .getLines()
      .toArray
      .flatMap(_.split(","))
      .groupBy(word => word)
      .map(tp => (tp._1, tp._2.size))
      .foreach(println)


    //函数的至简原则
    val arr: Array[Int] = Array(1, 2, 3, 4, 5)
    val res: Array[Int] = arr.map(_ * 10)


    arr.filter(_ % 2 == 0)


  }
}
